package com.muyu.controller;

import com.muyu.entity.UserEntity;
import com.muyu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: UserController
 * @Author: Zirun.Xin
 * @Date: 2024/12/30 19:03
 * @Version: 1.0
 * @Description: 用户管理控制层
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    /**
     * 用户业务层
     */
    @Autowired
    private UserService userService;

    /**
     * 不查询db所有用户信息
     */
    @GetMapping("/get-users")
    public List<UserEntity> getUserList1() {
        return userService.getUsers();
    }

    /**
     * 根据性别查询所有用户
     *
     * @param sex 性别
     */
    @GetMapping("/get-users-by-sex")
    public List<UserEntity> getUsersBySex(@RequestParam(name = "sex") String sex) {
        return userService.getUsersBySex(sex);
    }


    /**
     * 根据用户id查询用户信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/getUser-by-id")
    public UserEntity getUserById(@RequestParam(name = "userId") String userId) {
        return userService.getById(userId);
    }
}